from flask import *
import time

app = Flask(__name__)

app.config["SECRET_KEY"] = "akhjsdaskjdbiohadsnnanaslnksdaslnkas"


@app.route("/")
def index():
    print(current_app.config.get("SECRET_KEY"))
    return current_app.config.get("SECRET_KEY")


def set_session():
    session['name'] = 'zyd'
    return "<h1>set_session</h1>"


@app.route("/login")
def login():
    return "<h1>Login界面</h1>"


@app.route("/index")
def index2():
    return "<h1>index</h1>"


# 第一次请求之前
@app.before_first_request
def before_first_request():
    set_session()
    print("before_first_request")


# 执行视图函数之前 都会被执行
@app.before_request
def before_request():
    name = session.get('name')
    if not name:
        abort(404)


@app.errorhandler(404)
def errorhandler(e):
    return "<h1>你他妈没登录</h1>"


if __name__ == '__main__':
    app.run(debug=True)
